package com.example.eliminateifelse;

import com.example.eliminateifelse.designmode.AbstractCart;
import com.example.eliminateifelse.entity.Cart;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;

import java.util.HashMap;
import java.util.Map;

/**
 * @version 1.0.0
 * @className: TestIfCart
 * @description:
 * @author: zhangjunfa
 * @date: 2023/1/5 11:56
 */
public class TestIfCart {

    @Autowired
    private static ApplicationContext applicationContext;

    public static void main(String[] args) {
        Map<Long, Integer> items = new HashMap<>();
        int userId=1;
        String userCategory = getUserCategory(userId);
        AbstractCart cart = (AbstractCart) applicationContext.getBean(userCategory + "UserCart");
        Cart cart1= cart.process(userId, items);
        System.out.println("Cart:   " +cart1);
    }


    private static String getUserCategory(int userId) {
        if (userId == 1) {
            return "Vip";
        }
        if (userId == 2) {
            return "Internal";
        }
        return "Normal";
    }
}
